#include <rclcpp/rclcpp.hpp>
#include <std_msgs/msg/float64_multi_array.hpp>

class ObstacleSubscriber : public rclcpp::Node
{
public:
    ObstacleSubscriber()
    : Node("obstacle_subscriber")
    {
        // 创建订阅者，订阅 double_array_topic 话题
        subscription_ = this->create_subscription<std_msgs::msg::Float64MultiArray>(
            "obstacle_pub_topic", 10,
            std::bind(&ObstacleSubscriber::topic_callback, this, std::placeholders::_1)
        );
    }

private:
    void topic_callback(const std_msgs::msg::Float64MultiArray::SharedPtr msg)
    {
        RCLCPP_INFO(this->get_logger(), "Received an array of length %zu", msg->data.size());
        
        // 打印数组中的每个值
        for (size_t i = 0; i < msg->data.size(); ++i)
        {
            RCLCPP_INFO(this->get_logger(), "Element %zu: %f", i, msg->data[i]);
        }
    }

    rclcpp::Subscription<std_msgs::msg::Float64MultiArray>::SharedPtr subscription_;
};

int main(int argc, char * argv[])
{
    rclcpp::init(argc, argv);
    rclcpp::spin(std::make_shared<ObstacleSubscriber>());
    rclcpp::shutdown();
    return 0;
}
